package com.lingshu.app.ui.register;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.lingshu.app.BR;
import com.lingshu.app.R;
import com.lingshu.app.model.register.RegisterResponse;

import java.util.List;

/**
 * @author 于定金
 * @version 1.0
 * @Date 2024/1/10 15:11
 * @Description
 */
public class RegisterAdapter extends RecyclerView.Adapter<RegisterAdapter.ReportFragmentViewHolder> {
    private List<RegisterResponse> dataList;
    private Context context;

    public RegisterAdapter(Context context) {
        this.context = context;
    }

    public void setDataList(List<RegisterResponse> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ReportFragmentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding dataBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_register, parent, false);
        return new ReportFragmentViewHolder(dataBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull ReportFragmentViewHolder holder, int position) {
        holder.binding.setVariable(BR.registerItem, dataList.get(position));
        addViewClickListener(holder.binding.getRoot(), dataList.get(position), position);
        addDownloadClickListener(holder.binding.getRoot(), dataList.get(position), position);
        holder.binding.executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    /**
     * 添加监听回调
     *
     * @param root
     * @param itemData
     * @param position
     */
    public void addViewClickListener(View root, RegisterResponse itemData, int position) {

    }

    /**
     * @param root
     * @param itemData
     * @param position
     */
    public void addDownloadClickListener(View root, RegisterResponse itemData, int position) {

    }

    public class ReportFragmentViewHolder extends RecyclerView.ViewHolder {
        ViewDataBinding binding;

        public ReportFragmentViewHolder(@NonNull ViewDataBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
